home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************
- * GEMTERM V1.2
- * 1992 by Martin F. Gergeleit
- * placed in the public domain
- *
- * GEMTERM COMES WITH ABSOLUTELY NO WARRANTY, NOR WILL I BE LIABLE FOR ANY
- * DAMAGES INCURRED FROM THE USE OF IT. USE ENTIRELY AT YOUR OWN RISK!!!
- *********************************************************************/
-
- #include <string.h>
- #include <ctype.h>
- #include <gemfast.h>
- #include <osbind.h>
- #include <mintbind.h>
- #include "txtwin.h"
- #include "gemterm.h"
-
- #ifdef DEBUG
- #include <stdio.h>
- #endif
-
- extern int handle;
- extern char path[], file[];
- extern int default_font;
- extern int default_height;
- extern int max_font;
- extern short got_font;
- extern OBJECT *rs_trindex[];
- extern int tty;
- extern short tty_used;
- extern char args[];
- extern char default_cwd[];
- extern short default_pers;
- extern short default_keep;
- extern short default_conv;
- extern short do_dialog;
-
- static char c_line[136];
-
- do_select_dialog(win, cmd_line)
- txt_win *win;
- char **cmd_line;
- {
- int tmpx, tmpy, tmpw, tmph;
- int exit_button;
- int font_index;
- char font_name[32];
- int i, j, ret;
- int startobj;
- OBJECT *tree;
- TEDINFO *tname, *targs, *tdir, *tlines, *tcols, *thist;
-
- #ifdef DEBUG
- fprintf(stderr, "do_select_dialog starts\n");
- #endif
-
- tree = rs_trindex[0];
- tname = (TEDINFO *)tree[TNAME].ob_spec;
- targs = (TEDINFO *)tree[TARGS].ob_spec;
- tdir = (TEDINFO *)tree[TDIR].ob_spec;
- tlines = (TEDINFO *)tree[TLINES].ob_spec;
- tcols = (TEDINFO *)tree[TCOLS].ob_spec;
- thist = (TEDINFO *)tree[THIST].ob_spec;
-
- tree[BPROG].ob_state |= SELECTED;
- tree[TNAME].ob_state &= ~DISABLED;
- tree[TARGS].ob_state &= ~DISABLED;
- tree[TDIR].ob_state &= ~DISABLED;
- tree[BKEEP].ob_state &= ~DISABLED;
- tree[BTERM].ob_state &= ~SELECTED;
- tree[BPTY].ob_state &= ~SELECTED;
- tree[BOK].ob_state &= ~SELECTED;
- tree[BCANCEL].ob_state &= ~SELECTED;
- tree[BSAVE].ob_state &= ~SELECTED;
-
- if (default_pers)
- tree[BPERS].ob_state |= SELECTED;
- else
- tree[BPERS].ob_state &= ~SELECTED;
-
- if (default_keep)
- tree[BKEEP].ob_state &= ~SELECTED;
- else
- tree[BKEEP].ob_state |= SELECTED;
-
- if (default_conv)
- tree[BSCONV].ob_state |= SELECTED;
- else
- tree[BSCONV].ob_state &= ~SELECTED;
-
- win->real_pty = win->my_pty;
- if (tty_used)
- tree[BTERM].ob_state |= DISABLED;
- else
- tree[BTERM].ob_state &= ~DISABLED;
-
- for (font_index = 1; font_index <= max_font ; font_index++) {
- if (default_font == vqt_name(handle, font_index, font_name))
- break;
- }
-
- if (*cmd_line == 0) {
- strcpy(c_line, path);
- for (i = 0; c_line[i] != '\0'; i++)
- if (c_line[i] == '*')
- c_line[i] = '\0';
- strcat(c_line, file);
- *cmd_line = c_line;
- }
- strncpy(tname->te_ptext, *cmd_line, tname->te_txtlen);
- tname->te_ptext[tname->te_txtlen-1] = '\0';
-
- strncpy(targs->te_ptext, &args[1], targs->te_txtlen);
- targs->te_ptext[targs->te_txtlen-1] = '\0';
-
- strncpy(tdir->te_ptext, default_cwd, tdir->te_txtlen);
- tdir->te_ptext[tdir->te_txtlen-1] = '\0';
-
- if (do_dialog) {
- form_center(tree, &tmpx, &tmpy, &tmpw, &tmph);
- form_dial(FMD_START, 0, 0, 0, 0, tmpx, tmpy, tmpw, tmph);
-
- objc_draw(tree, SELECT, 8, tmpx, tmpy, tmpw, tmph);
- draw_font(font_name);
-
- startobj = TARGS;
- while ((exit_button = form_do(tree, startobj)) != BOK) {
- switch (exit_button) {
- case BPROG:
- objc_change(tree, TNAME, 0, tmpx, tmpy, tmpw, tmph,
- tree[TNAME].ob_state & ~DISABLED, 1);
- objc_change(tree, TARGS, 0, tmpx, tmpy, tmpw, tmph,
- tree[TARGS].ob_state & ~DISABLED, 1);
- objc_change(tree, TDIR, 0, tmpx, tmpy, tmpw, tmph,
- tree[TDIR].ob_state & ~DISABLED, 1);
- objc_change(tree, BKEEP, 0, tmpx, tmpy, tmpw, tmph,
- tree[BKEEP].ob_state & ~DISABLED, 1);
- startobj = TARGS;
- win->real_pty = win->my_pty;
- break;
- case BTERM:
- if (tty_used)
- break;
- objc_change(tree, TNAME, 0, tmpx, tmpy, tmpw, tmph,
- tree[TNAME].ob_state | DISABLED, 1);
- objc_change(tree, TARGS, 0, tmpx, tmpy, tmpw, tmph,
- tree[TARGS].ob_state | DISABLED, 1);
- objc_change(tree, TDIR, 0, tmpx, tmpy, tmpw, tmph,
- tree[TDIR].ob_state | DISABLED, 1);
- objc_change(tree, BKEEP, 0, tmpx, tmpy, tmpw, tmph,
- tree[BKEEP].ob_state | DISABLED, 1);
- startobj = TLINES;
- win->real_pty = tty;
- break;
- case BPTY:
- objc_change(tree, TNAME, 0, tmpx, tmpy, tmpw, tmph,
- tree[TNAME].ob_state | DISABLED, 1);
- objc_change(tree, TARGS, 0, tmpx, tmpy, tmpw, tmph,
- tree[TARGS].ob_state | DISABLED, 1);
- objc_change(tree, TDIR, 0, tmpx, tmpy, tmpw, tmph,
- tree[TDIR].ob_state | DISABLED, 1);
- objc_change(tree, BKEEP, 0, tmpx, tmpy, tmpw, tmph,
- tree[BKEEP].ob_state | DISABLED, 1);
- startobj = TLINES;
- win->real_pty = win->my_pty;
- break;
- case TNAME:
- form_dial(FMD_FINISH, 0, 0, 0, 0, tmpx, tmpy, tmpw, tmph);
- fsel_input(path, file, &i);
- if (i) {
- strcpy(c_line, path);
- for (i = 0; c_line[i] != '\0'; i++)
- if (c_line[i] == '*')
- c_line[i] = '\0';
- strcat(c_line, file);
- *cmd_line = c_line;
- strncpy(tname->te_ptext, *cmd_line, tname->te_txtlen);
- tname->te_ptext[tname->te_txtlen-1] = '\0';
- }
- form_dial(FMD_START, 0, 0, 0, 0, tmpx, tmpy, tmpw, tmph);
- objc_draw(tree, SELECT, 8, tmpx, tmpy, tmpw, tmph);
- draw_font(font_name);
- break;
- case PFONT:
- if (font_index < max_font) {
- font_index++;
- got_font = TRUE;
- }
- default_font = vqt_name(handle, font_index, font_name);
- default_font = vst_font(handle, default_font);
- default_height = vst_point(handle, default_height, &ret,&ret,&ret,&ret);
- draw_font(font_name);
- break;
- case TDIR:
- form_dial(FMD_FINISH, 0, 0, 0, 0, tmpx, tmpy, tmpw, tmph);
- fsel_input(default_cwd, "", &i);
- if (i) {
- for (i = 0; default_cwd[i] != '\0'; i++)
- if (default_cwd[i] == '*')
- default_cwd[i] = '\0';
- strncpy(tdir->te_ptext, default_cwd, tdir->te_txtlen);
- tdir->te_ptext[tdir->te_txtlen-1] = '\0';
- }
- form_dial(FMD_START, 0, 0, 0, 0, tmpx, tmpy, tmpw, tmph);
- objc_draw(tree, SELECT, 8, tmpx, tmpy, tmpw, tmph);
- draw_font(font_name);
- break;
- case MFONT:
- got_font = TRUE;
- if (font_index > 1)
- font_index--;
- default_font = vqt_name(handle, font_index, font_name);
- vst_font(handle, default_font);
- default_height = vst_point(handle, default_height, &ret, &ret,
- &ret, &ret);
- draw_font(font_name);
- break;
- case PSIZE:
- got_font = TRUE;
- for (i = 1; i < 32; i++) {
- if ((j = vst_point(handle, i,&ret,&ret,&ret,&ret)) > default_height) {
- default_height = j;
- break;
- }
- }
- draw_font(font_name);
- break;
- case MSIZE:
- got_font = TRUE;
- for (i = 31; i > 0; i--) {
- if ((j = vst_point(handle, i,&ret,&ret,&ret,&ret)) < default_height) {
- default_height = j;
- break;
- }
- }
- draw_font(font_name);
- break;
- case BCANCEL:
- form_dial(FMD_FINISH, 0, 0, 0, 0, tmpx, tmpy, tmpw, tmph);
- return -1;
- case BSAVE:
- form_dial(FMD_FINISH, 0, 0, 0, 0, tmpx, tmpy, tmpw, tmph);
- return 0;
- }
- }
- } /* if do_dialog */
-
- default_pers = win->persistent = ((tree[BPERS].ob_state & SELECTED) != 0);
- default_conv = win->backslash_conv = ((tree[BSCONV].ob_state & SELECTED) != 0);
- default_keep = win->keep_on_exit = ((tree[BKEEP].ob_state & SELECTED) == 0);
-
- if ((tree[BTERM].ob_state & SELECTED) || (tree[BPTY].ob_state & SELECTED))
- *cmd_line = 0;
-
- strcpy(&args[1], targs->te_ptext);
- *args = strlen(targs->te_ptext);
-
- win->lines = atoi(tlines->te_ptext);
- if (win->lines < MIN_LINES)
- win->lines = MIN_LINES;
- if (win->lines > MAX_LINES)
- win->lines = MAX_LINES;
-
- win->cols = atoi(tcols->te_ptext);
- if (win->cols < MIN_COLS)
- win->cols = MIN_COLS;
- if (win->cols > MAX_COLS)
- win->cols = MAX_COLS;
-
- win->hist_size = atoi(thist->te_ptext) * 1024;
-
- form_dial(FMD_FINISH, 0, 0, 0, 0, tmpx, tmpy, tmpw, tmph);
-
- return 1;
-
- #ifdef DEBUG
- fprintf(stderr, "do_select_dialog ends\n");
- #endif
- }
-
- char *my_itoa(n)
- register unsigned long n;
- {
- static char buffer[10];
- register char *p = buffer;
-
- do {
- *p++ = "0123456789"[n % 10];
- } while((n /= 10) > 0);
-
- *p = '\0';
- return(strrev(buffer));
- }
-
- draw_font(font_name)
- char *font_name;
- {
- char str[40];
- int temp[4];
- int x, y, w, h, ret;
- int fw, fh;
- OBJECT *tree;
-
- #ifdef DEBUG
- fprintf(stderr, "draw_font starts\n");
- #endif
-
- tree = rs_trindex[0];
-
- strcpy(str, my_itoa(default_height));
- strcat(str, "p ");
- strcat(str, font_name);
-
- objc_offset(tree, BFONT, &x, &y);
- w = tree[BFONT].ob_width;
- h = tree[BFONT].ob_height;
- vsf_interior(handle,0);
- vsf_style(handle,8);
- vsf_color(handle,0);
- vst_font(handle, default_font);
- vst_point(handle, default_height, &ret,&ret,&fw,&fh);
- vst_alignment(handle, 0, 5, &ret, &ret);
- set_clip(x, y, w, h);
-
- temp[0] = x;
- temp[1] = y;
- temp[2] = x + w - 1;
- temp[3] = y + h - 1;
- v_bar(handle,temp);
-
- v_gtext(handle, x + (w - fw*strlen(str))/2, y + (h - fh)/2, str);
-
- #ifdef DEBUG
- fprintf(stderr, "draw_font ends\n");
- #endif
- }
-